package cn.lhl.zj.text;

import cn.lhl.zj.Dept;
import cn.lhl.zj.Emp;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;

/**
 * Created by datou on 2017/2/6.
 */
public class text {
    public static void main(String[] args) {
//        Configuration cfg=new Configuration().configure();
//        SessionFactory sf=cfg.buildSessionFactory();
//        Session session=sf.getCurrentSession();
//        Transaction ts = session.beginTransaction();
//
//        ts.commit();
        Configuration cfg=new Configuration().configure();
        SessionFactory sf=cfg.buildSessionFactory();
        Session session=sf.getCurrentSession();
        Transaction ts = session.beginTransaction();
        Dept dept1=new Dept();
        dept1.setDname("文化部");
        Dept dept2=new Dept();
        dept2.setDname("小时不");
        Emp emp1=new Emp();
        emp1.setEname("小刘");
        Emp emp2=new Emp();
        emp2.setEname("小王");
        dept1.setEmp(emp1);
        emp2.setDept(dept2);
        dept2.setEmp(emp2);
        session.save(emp2);
//        Dept dept = session.get(Dept.class, 2);
//        System.out.println(dept.getEmp().getEname());
        ts.commit();


    }
}
